// 时间库dayjs
import * as dayjs from 'dayjs'

// 引入过滤选项
import { genderOptions, statusOptions, menuTypeOptions, orderStatusOptions, reportOptions, isureOptions, pickupMethodOptions, workOrderStatusOptions, workOrderSubmitStatusOptions, workOrderSourceStatusOptions, defaultAddressStatusOptions, isPayAgentMoneyOptions } from './options'

// 转换日期格式 ios
export function iso8601DateFormat(date, pattern = 'YYYY-MM-DD') {
    if (!date) return
    return dayjs(date).format(pattern)
}

// 转换日期时间格式 ios
export function iso8601DateTimeFormat(date, pattern = 'YYYY-MM-DD HH:mm:ss') {
    if (!date) return
    return dayjs(date).format(pattern)
}

// 转换时间格式 datetime毫秒
export function dateFormat(date, pattern = 'YYYY-MM-DD HH:mm:ss') {
    if (!date) return ''
    if (typeof date === 'string') date = Number(date)
    return dayjs(date).format(pattern)
}

// 转换时间格式 unix秒
export function unixDateFormat(date, pattern = 'YYYY-MM-DD HH:mm:ss') {
    if (!date) return ''
    if (typeof date === 'string') date = Number(date)
    return dayjs.unix(date).format(pattern)
}

// 文件格式名称返回
export function fileUrlToFileName(url) {
    const arr_name = url.split('/')
    const file_name = arr_name[arr_name.length - 1] // 获取文件名
    return file_name
}

/**
 *  性别格式化
 * @param status
 * @return String
 */
export function genderFormat(status) {
    let i = genderOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : genderOptions[i].label
    return label
}

/**
 * 手机号*脱敏
 * @param mobile
 * @return 135****2301
 */
export function filterMobile(val) {
    if (!val) return val
    return val.replace(/(\d{7})\d*(\d{0})/, '$1****$2')
}

// 权限菜单类型
export function filterMenuType(status) {
    let i = menuTypeOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : menuTypeOptions[i].label
    return label
}

// 数据状态class
export function filterStatusClass(status) {
    let i = statusOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? '' : statusOptions[i].class
    return label
}

// 数据状态
export function filterStatus(status) {
    let i = statusOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : statusOptions[i].label
    return label
}

// 订单状态
export function filterOrderStatus(status) {
    let i = orderStatusOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : orderStatusOptions[i].label
    return label
}

// 报备状态class
export function filterReportClass(status) {
    let i = reportOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : reportOptions[i].class
    return label
}

// 是否保价
export function filterIsureStatus(status) {
    let i = isureOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : isureOptions[i].label
    return label
}

// 取件方式
export function filterPickupMethod(status) {
    let i = pickupMethodOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : pickupMethodOptions[i].label
    return label
}

// 工单状态
export function filterWorkOrderStatus(status) {
    let i = workOrderStatusOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : workOrderStatusOptions[i].label
    return label
}

// 工单提交状态
export function filterWorkOrderSubmitStatus(status) {
    let i = workOrderSubmitStatusOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : workOrderSubmitStatusOptions[i].label
    return label
}

// 工单数据来源
export function filterWorkOrderSourceStatus(status) {
    let i = workOrderSourceStatusOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : workOrderSourceStatusOptions[i].label
    return label
}

// 默认地址
export function filterDefaultAddressStatus(status) {
    let i = defaultAddressStatusOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : defaultAddressStatusOptions[i].label
    return label
}

// 代理费支付状态
export function filterIsPayAgentMoney(status) {
    let i = isPayAgentMoneyOptions.findIndex(item => {
        return item.value === status
    })
    let label = i === -1 ? status : isPayAgentMoneyOptions[i].label
    return label
}
